package com.eastfair.imaster.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.imaster.dto.ConferenceUserPageQuery;
import com.eastfair.imaster.dto.ConferenceUserSaveDTO;
import com.eastfair.imaster.dto.ConferenceUserUpdateDTO;
import com.eastfair.imaster.entity.ConferenceUser;
import com.eastfair.imaster.service.ConferenceUserService;
import com.eastfair.imaster.vo.ConferenceUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 论坛报名人员
 * </p>
 *
 * @author zjn
 * @date 2021-08-31
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/conferenceUser")
@Api(value = "ConferenceUser", tags = "论坛报名人员")
public class ConferenceUserController extends SuperController<ConferenceUserService, Long, ConferenceUser, ConferenceUserPageQuery, ConferenceUserSaveDTO, ConferenceUserUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private ConferenceUserService conferenceUserService;

    @Override
    public void handlerResult(IPage<ConferenceUser> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<ConferenceUser> conferenceUserList = list.stream().map((map) -> {
            ConferenceUser conferenceUser = ConferenceUser.builder().build();
            //TODO 请在这里完成转换
            return conferenceUser;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(conferenceUserList));
    }

    /**
     * 获取论坛报名人员列表
     *
     * @param params 分页
     * @return
     */
    @GetMapping("/getPageList")
    @ApiOperation(value = "获取论坛报名人员列表", notes = "获取论坛报名人员列表")
    public R<Page<ConferenceUserVO>> getPageList(@RequestBody PageParams<ConferenceUserPageQuery> params) {
        return R.success(conferenceUserService.getPageList(params));
    }

}
